//
//  MoreViewController.m
//  HuiWenMovie
//
//  Created by niceDay on 15/7/17.
//  Copyright (c) 2015年 computer. All rights reserved.
//

#import "MoreViewController.h"


@interface MoreViewController ()
{
    SDImageCache *cache;
    UILabel *cashLable;
}
@end

@implementation MoreViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.navigationItem.title = @"更多";
    }
    return self;
}
#pragma mark - main

- (void)viewDidLoad {
    [super viewDidLoad];
    [self _createTableView];
    [self _loadData];
   
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated{
    [_tableView reloadData];
}

#pragma mark - _createSubviews
- (void)_createTableView{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Kwidth, Kheight) style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = [UIColor blackColor];
    cashLable = [[UILabel alloc] initWithFrame:CGRectMake(Kwidth-Kwidth/6*1.5,20, Kwidth/6, 20)];

    [self.view addSubview:_tableView];
}


- (void)_loadData{
    _titleArray = @[@"清除缓存",@"给个评价",@"检查最新版本",@"商务合作",@"欢迎页",@"关于"];
    _imageArray = @[@"moreClear@2x",@"moreScore@2x",@"moreVersion@2x",@"moreBusiness@2x",@"moreWelcome@2x",@"moreAbout@2x"];
}

#pragma mark - delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _titleArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    }
    cell.backgroundColor = [UIColor blackColor];
    cell.imageView.image = [UIImage imageNamed:_imageArray[indexPath.row]];
    cell.textLabel.text = _titleArray[indexPath.row];
    cell.textLabel.textColor = [UIColor whiteColor];
    if (indexPath.row == 0) {
         cashLable.text = @"0";
        cache = [SDImageCache sharedImageCache];
        CGFloat size = [cache getSize];
        cashLable.text = [NSString stringWithFormat:@"%.1lf M",size/1000/1000];
        cashLable.textColor = [UIColor whiteColor];
        [cell.contentView addSubview:cashLable];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"确认清除缓存" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
    [alert show];
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1) {
        [cache clearDisk];
        [_tableView reloadData];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
